package com.itheima.homework6_Function2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

public class Demo_Function2 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("张三", 85);
        map.put("李四", 80);
        map.put("王五", 90);
        map.put("赵六", 95);
        map.put("田七", 70);
        //1、将Map<String, Integer>中所有的值存到ArrayList<Integer>中
        Function<Map<String, Integer>, ArrayList<Integer>> fun1 = s -> new ArrayList<>(s.values());
        ArrayList<Integer> list = fun1.apply(map);
        System.out.println(list);
        //2、求存储元素为Integer类型的ArrayList中所有元素的平均数
        Function<ArrayList<Integer>,Integer> fun2 = s->{
            int count = 0;
            for (Integer i : s) {
                count += i;
            }
            return count/s.size();
        };
        Integer ave = fun2.apply(list);
        System.out.println(ave);

    }
}
